const tokens = {
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  },
  visitor: {
    token: 'visitor-token'
  }
}

const users = {
  'admin-token': {
    roles: ['admin'],
    role: 'admin',
    introduction: 'I am a super administrator',
    avatar:
      'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'admin'
  },
  'editor-token': {
    roles: ['editor'],
    role: 'editor',
    introduction: 'I am an editor',
    avatar:
      'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Normal Editor'
  },
  'visitor-token': {
    roles: ['visitor'],
    role: 'visitor',
    introduction: 'I am an visitor',
    avatar:
      'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Normal visitor'
  }
}

export default [
  // user login
  {
    url: 'user/login',
    type: 'post',
    response: config => {
      const { username } = config.body
      const token = tokens[username]
      console.log(token)
      // mock error
      if (!token) {
        return {
          code: 60204,
          message: 'Username and password are incorrect.'
        }
      }

      return {
        code: 200,
        data: token
      }
    }
  },

  // get user info
  {
    url: '/user/info',
    type: 'post',
    response: config => {
      console.log(config)
      // const { token } = config.query
      // const { token } = 'admin-token'
      const info = users['admin-token']
      console.log(info)
      // mock error
      if (!info) {
        return {
          code: 50008,
          message: 'Login failed, unable to get user details.'
        }
      }

      return {
        code: 200,
        data: info
      }
    }
  },

  // user logout
  {
    url: '/user/logout',
    type: 'post',
    response: _ => {
      return {
        code: 200,
        data: 'success'
      }
    }
  },
  // user infoList
  {
    url: '/user/info/list',
    type: 'get',
    response: config => {
      console.log(config)
      return {
        code: 200,
        data: {
          total: 2,
          items: [
            {
              id: 0,
              createTime: '2019-06-08',
              username: 'admin1',
              name: '11',
              role: 'admin'
            },
            {
              id: 1,
              createTime: '2019-06-07',
              username: 'admin2',
              name: '22',
              role: 'admin'
            }
          ]
        }
      }
    }
  }
]
